<template>
  <div class="users">
        <Button type="primary" @click="addData">添加数据</Button>
        <Button type="error" @click="removesData">删除多条</Button>
        <Input search v-model="name" placeholder="请输入关键字" @on-search="searchData"/>

        <Table :columns="columns" :data="listData" @on-selection-change="onSelectionChange"></Table>
        <Page :total="total" show-sizer @on-change="onChangePage" @on-page-size-change="onPageSizeChange" :page-size-opts="[5,10,20,30,40,50]"/>
        <Modal
        v-model    = "modal1"
        title      = "Common Modal dialog box title"
        @on-ok     = "ok"
        @on-cancel = "cancel">
        <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
            <FormItem label="Name" prop="name">
                <Input v-model="formValidate.name" placeholder="Enter your name"></Input>
            </FormItem>
            <FormItem label="Password" prop="password">
                <Input v-model="formValidate.password" placeholder="Enter your password"></Input>
            </FormItem>
            <FormItem label="Age" prop="age">
                <Input v-model="formValidate.age" placeholder="Enter your age"></Input>
            </FormItem>
            <FormItem label="Chart" prop="chart">
                <Input v-model="formValidate.chart" placeholder="Enter your chart"></Input>
            </FormItem>
            <FormItem label="Sex" prop="sex">
                <Input v-model="formValidate.sex" placeholder="Enter your sex"></Input>
            </FormItem>
             <FormItem label="Email" prop="email">
                <Input v-model="formValidate.email" placeholder="Enter your email"></Input>
            </FormItem>
             <FormItem label="Love" prop="love">
                <Input v-model="formValidate.love" placeholder="Enter your love"></Input>
            </FormItem>
            <FormItem label="Appearance" prop="appearance">
                <Input v-model="formValidate.appearance" placeholder="Enter your appearance"></Input>
            </FormItem>
            <FormItem>
                <Button type="primary" @click="handleSubmit('formValidate')">Submit</Button>
                <Button @click="handleReset('formValidate')" style="margin-left: 8px">Reset</Button>
            </FormItem>
        </Form>
    </Modal>
  </div>
</template>

<script>
import  { Base } from '../mixins/Base'
export default {
  mixins:[Base],
  data(){
    return {
      formValidate: {
          name    : '',
          password: '',
          age:"",
          chart:"",
          sex:"",
          email:"",
          love:"",
          appearance:""
      },
      ruleValidate: {
          name: [
              { required: true, message: 'The name cannot be empty', trigger: 'blur' }
          ],
          password: [
              { required: true, message: 'password cannot be empty', trigger: 'blur' },
          ],
          age: [
              { required: true, message: 'age cannot be empty', trigger: 'blur' },
          ],
          chart: [
              { required: true, message: 'chart cannot be empty', trigger: 'blur' },
          ],
           sex: [
              { required: true, message: 'sex cannot be empty', trigger: 'blur' },
          ],
           email: [
              { required: true, message: 'email cannot be empty', trigger: 'blur' },
              { type: 'email', message: 'Incorrect email format', trigger: 'blur' }
          ],
          love: [
              { required: true, message: 'love cannot be empty', trigger: 'blur' },
          ],
          appearance: [
              { required: true, message: 'appearance cannot be empty', trigger: 'blur' },
          ],
      },
      columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
              title: '姓名',
              key  : 'name'
          },
          {
              title: '密码',
              key  : 'password'
          },
          {
              title: '年龄',
              key  : 'age'
          },
           {
              title: '微信',
              key  : 'chart'
          },
          {
              title: '性别',
              key  : 'chart'
          },
          {
              title: '邮箱',
              key  : 'email'
          },
           {
              title: '爱好',
              key  : 'love'
          },
          {
              title: '颜值',
              key  : 'appearance'
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
                return h('div', [
                    h('Button', {
                        props: {
                            type: 'primary',
                            size: 'small'
                        },
                        style: {
                            marginRight: '5px'
                        },
                        on: {
                            click: () => {
                                // this.show(params.index)
                                this.editData(params.row._id);
                            }
                        }
                    }, '修改'),
                    h('Button', {
                        props: {
                            type: 'error',
                            size: 'small'
                        },
                        on: {
                            click: () => {
                                this.removeData(params.row._id);
                            }
                        }
                    }, '删除')
                ]);
            }
        }
      ]
    }
  }
}
</script>
